import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import Index from '../views/index.vue'
import Icontiaozhuan from '../views/icontiaozhuan.vue'
import pinpaixiangxi from '../views/pinpaixiangxi.vue'
import xinpinshoufa from '../views/xinpinshoufa.vue'
import cuowu from '../views/cuowu.vue'
import zhuanti from '../views/zhuanti.vue'
import fenlei from '../views/fenlei.vue'
import fenleiid from '../views/fenlei.vue'
import tubiaoxiangxi from '../views/tubiaocanpinxiangxi.vue'
import user from '../views/user.vue'
import cart from '../views/cart.vue'
///////////////////$360Section
// import dlzc from '../App2.vue'
// import dl from '../views/denglu.vue'
// import zc from '../views/zhuce.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: Index,
    children:[
      {
        path:'/index/popup',
        name:'popup',
        component: () => import(/* webpackChunkName: "index" */ '../views/searchpopup.vue')
      }
    ]
  },
  {
    path:'/icontiaozhuan/:id',
    name:'icontiaozhuan',
    component:Icontiaozhuan
  },
  {
    path:'/pinpaixiangxi/:id',
    name:'pinpaixiangxi',
    component: pinpaixiangxi
  },
  {
    path:'/xinpinshoufa/:id',
    name:'xinpinshoufa',
    component: xinpinshoufa
  },
  {
    path:'/404',
    name:'404',
    component: cuowu  },
    {
      path:'/zhuanti',
      name:'zhuanti',
      component: zhuanti
     },
     {
      path:'/fenlei',
      name:'fenlei',
      component: fenlei
     },
     {
      path:'/fenlei/:id',
      name:'fenleiid',
      component: fenleiid
     },  
     {
      path:'/tubiaoxiangxi/:id',
      name:'tubiaoxiangxi',
      component: tubiaoxiangxi
     },
     {
      path:'/user',
      name:'user',
      component: user
     },
     {
      path:'/cart',
      name:'cart',
      component: cart
     },

  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
  // {
  //   path:'/dlzc',
  //   name:'dlzc',
  //   component: dlzc,
  //   children:[
  //     {
  //       path:'/dl',
  //       name:'dl',
  //       component: dl
    
  //     },
  //     {
  //       path:'/zc',
  //       name:'zc',
  //       component:zc
    
  //     }
  //   ]
  //   }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to,from,next)=>{
  let token =  localStorage.getItem('token')
  if(to.path=='/cart'){
        if(token){
          next()
        }else{
          next('/user')
        }
  }else{
    next()
  }

})


export default router
